
 let a:number
 a=11
 a=21311111111
 let b:string;
 let c:boolean = true;
 function sum(a,b):number{
     return a+b;
 }
sum(123,'789')
console.log(sum(122,333))
//字面量声明
let d:"male" | "female";
d="male"
let e: string | boolean
e=true
e="hellow"
//当一个变量被设置为any时，等于关闭了其ts类型检测
let h:any;//=let h;
h=10
h=true
h="sss"
let k:unknown;
k="dddd"
let s:string
s=h//any可以赋值给别的变量
//s=k//unkonw类型的变量不能赋值给其他变量，等于安全的any
if(typeof k === 'string'){
    s = k;
}
//类型断言
s = k as string;
// s = <string> k;
//void用来表示空，以函数为例，表示没有返回值的函数
function fn():void{

}
//never 表示不会返回结果
function fn2():never{
    throw new Error('报错了！')
}
let y:object;
y = {}
y = function (){
}
//在属性名加问号表示可选
let x:{name:string,age?:number}
x = {name:'孙悟空',age:18}
//[porp:string]:any表示任意类型的属性
let z:{name:string,[porp:string]:any}
z={name:'猪八戒',age:12,hhh:'ddd'}
let r:(a:number,b:number)=>number
r= function(n1,n2):number{
    return n1 + n2
}
//数组的两种声明方式
let arr1:string[];
let arr2:Array<number>
arr2 = [1,2,3]
//元组=》固定长度的数组
let tuple :[string,string]
tuple = ['hellow','world']
//enum枚举

enum Gender{
    male=1,
    female=0
}
let i :{name:string,gender:Gender}
i = {
    name:'孙悟空',
    gender:Gender.male
}
console.log(i.gender === Gender.male)

let J:{name:string} & {age:number}
J ={name:'孙悟空',age:18}


//类型的别名
type Mytype = 1|2|3|4|5;
let kk:Mytype;

kk=2



function testit<T>(arg: T): T {  console.log(kk) // Error
    return arg
  }












